package com.project.grenting.controller;


import com.project.grenting.pojo.Housing;
import com.project.grenting.service.housing.HousingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/housing")
public class HousingController {



    @Resource
    private HousingService housingService ;

    @RequestMapping("/housingList")
    @RequiresPermissions("housingList")
    public String userList(Model model) {

        List<Housing> housingList = housingService.getAllHousings() ;
        model.addAttribute("housingList", housingList) ;

        return "housing/housingList" ;
    }




    @RequestMapping("/housingAdd")
    @RequiresPermissions("housingAdd")
    public String housingAdd(Model model) {
        List<Housing> housingList = housingService.getAllHousings();
        model.addAttribute("housingList", housingList);

        return "housing/housingAdd";
    }

    @RequestMapping("/doHousingAdd")
    @RequiresPermissions("housingAdd")
    public String doHousingAdd(Housing housing, Model model) {

        /* Customer customerInfo = (Customer) SecurityUtils.getSubject().getSession().getAttribute("currentCustomer");*/
        /* System.out.println(customerInfo.getId()+"=============================");*/

        System.out.println(housing.toString());

        int success = housingService.addHousing(housing);
        String msg = "";
        if (success == 1) {
            msg = "添加用户成功";
        } else {
            msg = "添加用户失败";
        }
        model.addAttribute("msg", msg);

        return "forward:/housing/housingAdd";
    }


}
